home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / fansi.zip / UNSETRAW.ASM < prev    next >
Assembly Source File  |  1986-06-02  |  3KB  |  140 lines

  1. page 66, 132
  2. ; unsetraw.com
  3. ; usage: unsetraw {x}
  4. ;  If x is given, sets raw mode; otherwise, sets cooked mode.
  5. ;  Useful only to get back to cooked mode after stupid program has left
  6. ;  console in raw mode (like, say, when you ^C out of more.com).
  7. ; It's a bit overblown because I used a more complicated program
  8. ; as a pattern.
  9.  
  10. ; uses args
  11.     extrn    _args:near,    _shift:near
  12.     extrn    argc:word,    argv:word
  13.  
  14. dos    macro    fn
  15.     mov    ah, fn
  16.     int    21h
  17.     endm
  18.  
  19. stdin    equ    0
  20. stdout    equ    1
  21. stderr    equ    2
  22.  
  23. code    segment para public 'CODE'
  24. assume cs:code,ds:code
  25.  
  26.     org    100h
  27. main    proc
  28.     jmp    unsetraw
  29. main    endp
  30.  
  31.  
  32. ;----------------------------------------------
  33.  
  34.     db    27
  35.     db    '[2Junsetraw (C) 1984 Yoyodyne, Inc- a growing excited company.'
  36.     db    13, 10
  37.     db    'Usage: unsetraw {x}', 13, 10
  38.     db    '  If x is given, sets console to RAW mode; else sets COOKED mode.'
  39.     db    13, 10
  40.     db    '  Useful for recovering from programs which leave console in raw mode.'
  41.     db    13, 10
  42.     db    26
  43.  
  44. errs        dw    null        ; error zero- no error
  45.         dw    null, filenotfound, pathnotfound, nohand, access
  46.         dw    null, null, null, null, null
  47.         dw    null, null, null, null, baddrive
  48.         dw    null, null
  49.  
  50. null        db    '?dos err', 0
  51. filenotfound    db    'File not found', 0
  52. pathnotfound    db    'Path not found', 0
  53. nohand        db    'No handles left', 0
  54. access        db    'Access denied', 0
  55. baddrive    db    'Invalid drive specification', 0
  56.  
  57. trueargc    dw    ?
  58.  
  59. ;--- strlen ---
  60. ; Returns length of ES:DI in CX, points to null with DI.
  61.  
  62. strlen    proc    near
  63.     cld
  64.     push    ax
  65.     mov    cx, -1
  66.     mov    al, 0
  67.     repnz    scasb
  68.     not    cx
  69.     pop    ax
  70.     ret
  71. strlen    endp
  72.  
  73. dos_err proc    near
  74.     mov    bx, ax
  75.     add    bx, ax
  76.     mov    di, errs[bx]
  77.     push    di
  78.     call    strlen
  79.     pop    dx
  80.     mov    bx, stderr
  81.     DOS    40h
  82.     ret
  83. dos_err endp
  84.  
  85. open_err    proc    near
  86.     call    dos_err
  87.     mov    al, 1
  88.     jmp     exit
  89. open_err    endp
  90.  
  91. ;-------------------------------------------------
  92.  
  93. unsetraw    proc    near
  94.  
  95.     call    _args
  96.  
  97.     ; if (argc > 0) ioctrl(stdout, binary)
  98.     ; else ioctrl(stdout, ascii);
  99.     cmp    argc, 0
  100.     jz    set_ascii
  101.  
  102.     ; Set binary mode on stdout.
  103.     mov    bx, stdout
  104.     mov    al, 0
  105.     DOS    44h        ; get tty bits
  106.     jc    open_err
  107.     or    dl, 32        ; set binary mode
  108.     mov    dh, 0
  109.     mov    al, 1
  110.     DOS    44h
  111.     jc    open_err
  112.     mov    al, 0
  113.     jmp    exit
  114.  
  115. set_ascii:
  116.     ; Set text mode on stdout.
  117.     mov    al, 0
  118.     mov    bx, 1
  119.     DOS    44h
  120.     jc    open_err
  121.     and    dx, 0cfh    ; set text mode
  122.     mov    al, 1
  123.     DOS    44h
  124.     jc    open_err
  125.     mov    al, 0        ; no error
  126.  
  127. exit:
  128.     mov    ah, 4ch
  129.     int    21h        ; terminate process, return status in AL.
  130.  
  131. unsetraw    endp
  132.  
  133. code    ends
  134.  
  135.     end    main
  136.  
  137.  
  138.  
  139.  
  140.